/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelEthernet.java
 *
 * Created on 12/03/2011, 18:34:21
 */

package tsb.UI.Paneles;


import tsb.dominio.enumeraciones.AsignacionIP;
import tsb.dominio.interfaces.IP;
import tsb.dominio.interfaces.Serial;


/**
 *
 * @author Federico Gomez
 */
public class PanelSerial extends javax.swing.JPanel {

    /** Creates new form PanelEthernet */
    public PanelSerial() {
        initComponents();
    }

    public boolean verificar()
    {
       if(!this.panelInterfaces.verificar())
           return false;
       
       return true;
    }
     
     public Serial getSerial()
     {
          boolean estado=this.panelInterfaces.estado();

        int anchoBanda= this.panelInterfaces.getAnchoDeBanda();

        IP IP= this.panelInterfaces.getIP();

        IP mascara= this.panelInterfaces.getMascara();
        
        String a=this.cmbClockRate.getSelectedItem().toString();

        Serial et = new Serial(estado, anchoBanda, IP, mascara,Integer.parseInt(a));
        
        return et;
     }
     
     public void setAsignacion(AsignacionIP asigancion)
    {
        this.panelInterfaces.setAsignacionIP(asigancion);
        
    }
     
     
     public void setCampos(Serial e)
    {
        if(e.getEstado())
        {
            panelInterfaces.setEncendido("Si");
        }
        else
        {
            panelInterfaces.setEncendido("No");
        }

         panelInterfaces.setAnchoBada(e.getAnchoDeBanda());
         panelInterfaces.setIP(e.getIp());
         panelInterfaces.setMascara(e.getSubNetMask());

       int clock= e.getClockRate();
       if(clock==1200)
       {
           this.cmbClockRate.setSelectedIndex(0);
       }
       if(clock==2400)
       {
           this.cmbClockRate.setSelectedIndex(1);
       }
       if(clock==4800)
       {
           this.cmbClockRate.setSelectedIndex(2);
       }
       if(clock==9600)
       {
           this.cmbClockRate.setSelectedIndex(3);
       }
       if(clock==19200)
       {
           this.cmbClockRate.setSelectedIndex(4);
       }
       if(clock==38400)
       {
           this.cmbClockRate.setSelectedIndex(5);
       }
       if(clock==56000)
       {
           this.cmbClockRate.setSelectedIndex(5);
       }
       if(clock==64000)
       {
           this.cmbClockRate.setSelectedIndex(6);
       }
   }
    
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bgroupDuplex = new javax.swing.ButtonGroup();
        jLabel2 = new javax.swing.JLabel();
        cmbClockRate = new javax.swing.JComboBox();
        panelInterfaces = new tsb.UI.Paneles.PanelInterfaces();

        setBackground(new java.awt.Color(255, 255, 255));
        setBorder(javax.swing.BorderFactory.createTitledBorder("Serial"));

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel2.setText("Clock Rate:");

        cmbClockRate.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1200", "2400", "4800", "9600", "19200", "38400", "56000", "64000", "72000", "125000", "128000", "250000", "500000", "800000", "1000000", "1300000", "2000000", "4000000", "Not Set" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cmbClockRate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(panelInterfaces, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(52, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(panelInterfaces, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(cmbClockRate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(58, 58, 58))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup bgroupDuplex;
    private javax.swing.JComboBox cmbClockRate;
    private javax.swing.JLabel jLabel2;
    private tsb.UI.Paneles.PanelInterfaces panelInterfaces;
    // End of variables declaration//GEN-END:variables

}
